package com.heima.gateway.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.RequestPath;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @Author: Serendipity-li
 * @Date: 2024/7/31 - 21:30
 * @Description: com.heima.gateway.filter
 */
@Component
public class MyGlobalFilter implements GlobalFilter, Ordered {
    /*
     * @description:全局过滤器
     * @author: louis-li
     * @date: 2024/7/31 21:31
     * @param: [exchange, chain]
     * @return: reactor.core.publisher.Mono<java.lang.Void>
     **/
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        RequestPath path = exchange.getRequest().getPath();
        System.out.println("path = " + path);
        return chain.filter(exchange);
    }


    @Override
    public int getOrder() {
        //过滤器执行顺序，值越小优先级越高
        return 0;
    }
}
